﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Vit.Web.Mvc
{
    public class FilterRegistryItem
    {
        private readonly List<IFilterCriteria> filterCriteria;
        public Type FilterType { get; private set; }

        public FilterRegistryItem(IEnumerable<IFilterCriteria> filterCriteria, Type filterType)
        {
            this.filterCriteria = new List<IFilterCriteria>(filterCriteria);
            FilterType = filterType;
        }

        public bool Match(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            return filterCriteria.Aggregate(true, (prev, f) => prev ? f.Match(controllerContext, actionDescriptor) : prev);
        }
    }
}
